<?php

class Default_Model_User extends Zend_Db_Table_Abstract{
    public $_name="user";        
    public function getDataByUserId($userId){
    	$query = $this->select()
                        ->setIntegrityCheck(false)
                        ->from(array('u'=>$this->_name),array('u.userId','u.email','u.username','u.password','u.fullName','u.mobile','u.status','u.address','u.sex','u.birth'))
                        ->where('userId = ?',(int)$userId);                                
        return $this->fetchRow($query);        
    }    
    public function getDataByUsername($username){        
    	$query = $this->select()
                        ->from(array('u'=>$this->_name),array('u.userId','u.email','u.username','u.password','u.fullName','u.mobile','u.status','u.address','u.sex','u.birth'))
                        ->where("username = '".$username."'");                                
        return $this->fetchRow($query);
    }
    public function getDataByEmail($email){        
    	$query = $this->select()
                        ->from(array('u'=>$this->_name),array('u.userId','u.email','u.username','u.password','u.fullName','u.mobile','u.status','u.address','u.sex','u.birth'))
                        ->where("email = '".$email."'");                                
        return $this->fetchRow($query);
    }
    public function addData($data){
        $data = array('email'  => $data['email'],
                'fullName'        => $data['fullName'],
                'password'         =>$data['password']);                
        $idAdd = $this->insert($data);        
        return $idAdd;
    }
    public function updateStatus($userId){
        $this->update(array('status'=>'1'),'userId = '.$userId);                        
    }
    public function changePass($paswd,$userId){        
        $this->update(array('psssword'=>$paswd),'userId = '.$userId);                        
    }
    public function updateData($data,$userId){        
        $this->update($data,'userId = '.$userId);                        
    }
    public function getDataConfirm($hash){        
    	$query = $this->select()
                        ->from(array('u'=>$this->_name),array('u.userId','u.email','u.username','u.password','u.fullName','u.mobile','u.status','u.address','u.sex','u.birth'))
                        ->where("random = '".$hash."'")
                        ->where("status = 0");                              
        return $this->fetchRow($query);
    }
    
}